<?php
$id = $_GET['id'];
$gig = safe_query("SELECT item.id, title, content, price, category, image, owner, rating.rating_min, rating.rating_max FROM item INNER JOIN rating ON item.id = rating.id WHERE item.id='".$id."'");
$reviews = safe_query("SELECT * FROM reviews WHERE gig='".$id."' LIMIT 0,10");

$reviews_data = '';
if(mysql_num_rows($gig))
{	 
	$ds = mysql_fetch_array($gig);
	$owner = username($ds['owner']);
	$category = category($ds['category']);
	
	//----Reviews----
	$r_count = mysql_num_rows($reviews);
	$r_positive = mysql_num_rows(safe_query("SELECT rating FROM reviews WHERE gig='".$id."' AND rating=1"));
	$r_negative = mysql_num_rows(safe_query("SELECT rating FROM reviews WHERE gig='".$id."' AND rating=0"));
	if($r_count)
	{
		while($review = mysql_fetch_array($reviews))
		{
			$rating = 'negative';
			if($review['rating'])
				$rating = 'positive';
			$user = username($review['user']);
			
			$reply_q = "SELECT * FROM reviews WHERE gig='".$id."' AND reply='".$review['id']."'";
			if(mysql_num_rows(safe_query($reply_q)))
			{
				$reply = mysql_fetch_array(safe_query($reply_q));
				$reply_user = username($reply['user']);
				
				eval ("\$review_main = \"".gettemplate("gig/review_main")."\";");
				$reviews_data .= $review_main;
				
				eval ("\$review_main = \"".gettemplate("gig/review_main_reply")."\";");
				$reviews_data .= $review_main;
			}
			else
			{
				if($review['reply'] == 0)
				{
					eval ("\$review_main = \"".gettemplate("gig/review_main")."\";");
					$reviews_data .= $review_main;
				}
			}
		}
		$load = '<a href="#" class="more-review">Load more</a>';
	}
	
}
else //Gig does not exist
{
redirect('index.php', '', 0);
}

eval ("\$head = \"".gettemplate("gig/head")."\";");
eval ("\$main = \"".gettemplate("gig/main")."\";");
eval ("\$review_head = \"".gettemplate("gig/review_head")."\";");
eval ("\$review_main = \"".gettemplate("gig/review_main")."\";");
eval ("\$review_foot = \"".gettemplate("gig/review_foot")."\";");
eval ("\$foot = \"".gettemplate("gig/foot")."\";");

echo $head;
echo $main;
echo $review_head;
echo $reviews_data;
echo $review_foot;
echo $foot;


		
?>